package qrcode_type

import (
	"gitee.com/xlizy/common-go/base/enums"
	"strconv"
)

type QRCodeType int

const (
	QRDefault QRCodeType = iota + 1
	QR00001
	QR00002
)

func (e QRCodeType) Code() int32 {
	return int32(e)
}

func (e QRCodeType) Des() string {
	return enums.BE(e).Des
}

func (e QRCodeType) Enum() string {
	return enums.BE(e).Enum
}

func (e QRCodeType) Val() int {
	return int(e)
}

func (e *QRCodeType) UnmarshalJSON(value []byte) error {
	*e = QRCodeType(enums.UnmarshalEnum(value))
	return nil
}

func (e QRCodeType) MarshalJSON() ([]byte, error) {
	switch e {
	case QRDefault:
		return enums.JsonObj(int(e), "QRDefault", "默认")
	case QR00001:
		return enums.JsonObj(int(e), "QR00001", "哒哒音悦-查看资产")
	case QR00002:
		return enums.JsonObj(int(e), "QR00002", "营销系统-用户优惠券")
	}
	return []byte(strconv.Itoa(int(e))), nil
}

func SelectOptions() []enums.SelectOptions {
	return enums.ToSelectOptions([]any{QRDefault, QR00001, QR00002})
}
